﻿using MongoDB.Driver;
using Sustainalytics.ClientDW.Entities;
using System.Threading.Tasks;

namespace Sustainalytics.ClientDW.Synchronization.SyncHbaseData.CorporateDataLogic
{
    public static class CorporateDataCommand
    {
        public static async Task RecreateIndexes(IMongoCollection<CorporateData> corporateDataCollection)
        {
            CreateIndexOptions collationOptions = new CreateIndexOptions() { Collation = new Collation(locale: "en", caseLevel: true, strength: CollationStrength.Primary) };
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.Id)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.CompanyName)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Descending(x => x.CompanyName), collationOptions).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.CompanyNameLowercase)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.CompanyType)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.TemplateType)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.Country)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.Region)).ConfigureAwait(false);

            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.PeerGroup)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.SustainalyticsSector)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.SustainalyticsIndustryGroup)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.SustainalyticsIndustry)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.SustainalyticsSubIndustry)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.CapitalIqId)).ConfigureAwait(false);

            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Ascending(x => x.TotalEmployees)).ConfigureAwait(false);

            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Descending(x => x.ComprehensiveEsgResearchState.HasResearch)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Descending(x => x.CoreEsgResearchState.HasResearch)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Descending(x => x.ControversyResearchState.HasResearch)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Descending(x => x.CorporateGovernanceResearchState.HasResearch)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Descending(x => x.ProductInvolvementResearchState.HasResearch)).ConfigureAwait(false);
            await corporateDataCollection.Indexes.CreateOneAsync(Builders<CorporateData>.IndexKeys.Descending(x => x.RiskRatingResearchState.HasResearch)).ConfigureAwait(false);
        }
    }
}
